package ptij.vocoder.baseModel.common;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// Fork
/**

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class Fork extends TypedAtomicActor {

    public Fork(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        input = new TypedIOPort(this, "input", true, false);
        input.setTypeEquals(BaseType.OBJECT);

        output1 = new TypedIOPort(this, "output1", false, true);
        output1.setTypeEquals(BaseType.OBJECT);
        
        output2 = new TypedIOPort(this, "output2", false, true);
        output2.setTypeEquals(BaseType.OBJECT);
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort input;

    // Output Ports
    public TypedIOPort output1;
    public TypedIOPort output2;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
    }

    public void fire() throws IllegalActionException {
        ObjectToken obj = (ObjectToken) input.get(0);
        Short [] frame = (Short []) obj.getValue();

        Short [] newframe1 = new Short[frame.length/2];
        Short [] newframe2 = new Short[frame.length/2];

        for(int i = 0;i < frame.length/2;i++) {
            newframe1[i] = frame[i];
            newframe2[i] = frame[frame.length/2 + i];
        }

        output1.broadcast(new ObjectToken(newframe1));
        output2.broadcast(new ObjectToken(newframe2));
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////


    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

}
